package pe.bn.WSServiceHost.serHost.model;

import javax.xml.rpc.holders.StringHolder;
import pe.bn.WSServiceHost.serHost.interactive.WSConnect;


public class WSConsultaMultiRed {

	private HeadRequest cabeceraRequest;
	private BodyConsultaMultired body;
	
	public WSConsultaMultiRed(HeadRequest cab,BodyConsultaMultired input) {
		super();
		cabeceraRequest = cab;
		body = input;
	}
	
	public int EjecutarTramaHost(
			HeadRespose cabeceraRespose
			,BodyConsultaMultired outPut) throws Exception {

		String cadenaHost = new String();
		StringHolder cadenaResult = new StringHolder();		
		WSConnect wsConnect  =  new WSConnect();
		cadenaHost = cabeceraRequest.toString() + body.toString() ;
		int result = 9999;
		result =  wsConnect.EjecutarTramaHost(cadenaHost,cadenaResult);
		
		int longitudHead = cabeceraRequest.LongitudTrama();
		int longitudresult =cadenaResult.value.length();
		
		if (longitudresult >= longitudHead){
			String HeadResult = cadenaResult.value.substring(0,longitudHead);
			cabeceraRespose.FillCabecera(HeadResult);
		}else{
			cabeceraRespose = null;
		};
		
		int longitudBody =  body.LongitudTrama();
		
		if ( longitudresult >= longitudHead + longitudBody){
			String BodyResult = cadenaResult.value.substring(longitudHead,longitudHead + longitudBody);
			outPut.FillBoby(BodyResult,body.getLdeudaMultired());
		}else{
			outPut = null;
		};
		return result;
	}
		
}
